package com.miracle.system.web;

import com.miracle.common.utils.SearchUtils;
import com.miracle.common.utils.SecurityUtils;
import com.miracle.system.base.domain.ResultMap;
import com.miracle.system.domain.SysOperatelog;
import com.miracle.system.service.SysOperatelogService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：miracle.cui
 * @description：TODO
 * @date ：2020/9/27 9:48
 */
@ApiModel(value = "操作日志管理")
@RestController
@RequestMapping("/system/log")
public class SysOperatelogController {

    @Autowired
    SysOperatelogService operatelogService;

    @ApiModelProperty(value = "操作日志列表")
    @GetMapping("/list")
    public ResultMap list(SysOperatelog operatelog){

        SearchUtils.startPage();
        List<SysOperatelog> operatelogList = operatelogService.selectOperatelogList(operatelog);
        return ResultMap.getPage(operatelogList);
    }

    @PostMapping
    public ResultMap add(@Validated @RequestBody SysOperatelog operatelog){

        operatelog.setCreateBy(SecurityUtils.getUserId());
        Integer rows = operatelogService.insertOperatelog(operatelog);
        return rows > 0 ? ResultMap.success() : ResultMap.error();
    }
}
